package com.syaccp.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.syaccp.model.SysDept;
import com.syaccp.model.SysUser;
import com.syaccp.request.SysDeptRequest;
import com.syaccp.request.SysUserRequest;
import com.syaccp.service.DeptService;
import com.syaccp.utils.Result;
import com.syaccp.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author lixin
 * @since 2023-07-02
 */
@Api(tags = "部门")
@RestController
@RequestMapping("/api/dept")
public class DeptController {

    @Resource
    private DeptService deptService;


    @ApiOperation(value="根据登录用户查询部门信息，用户信息不需要传递过来")
    @GetMapping("/selectDeptAll")
    public Result selectDeptAll(){
        SysUser sysUser= SecurityUtil.getLoginUser();
        return deptService.selectDeptListByUser(sysUser);
    }

    @GetMapping("/deptList")
    public Result deptList(){
        List<SysDeptRequest>list=deptService.getAllDepartments();
        return Result.success(list);
    }

    @PostMapping("/pageGetDept")
    @ResponseBody
    public Result pageGetDept(int index){
        PageInfo<SysDeptRequest> pageInfo=deptService.pageGetDept(index);
        System.out.println(pageInfo);
        return Result.success(pageInfo);
    }

    @PutMapping("/updateDept")
    @ResponseBody
    public Result updateDept(@RequestBody SysDeptRequest sysDeptRequest){
        int num=deptService.updateDept(sysDeptRequest);
        return Result.success(num);
    }

}

